import Global from '@/config/Global'

/**
 * 人脸识别
 * @constructor
 */
export function AliFaceCompar(userInfo,callback) {
  ehbAppJssdk.user.AliFaceCompar({
    name: userInfo.names,
    idCard: userInfo.idCards,
    success:function(res){
      let data = JSON.parse(res);
      if(data.resultStatus == "9000"){
        callback(data);
      }else {
        ehbAppJssdk.notice.alert({
          title: '提示',
          message: '您没有通过人脸识别认证，请重新提交信息！',
          buttonName: '收到',
        });
      }
    }
  });
}

/**
 * 发送请求
 * @param data
 * @param info
 * @returns {string}
 */
export function request({url, data,method='post',contentType='application/json',showPreloader=true}) {
  return new Promise((resolve, reject) => {
    if(showPreloader){
      ehbAppJssdk.notice.showPreloader({text: "正在查询中.."});
    }
    let header={};
    if(url.indexOf('https://prod-gateway.ehbapp.hubei.gov.cn/7c5c00ca152e4864b46c9c7e0f0e89ea')>=0){
      header={'contentType': contentType,'X-hbzw-Api-Key':'928ad93e-9a5d-40b3-9666-713f92a796e9'}
    }else if(url=='https://prod-gateway.ehbapp.hubei.gov.cn/c4e94dc796da4210b910ff93884c8e4a'){
      header={'contentType': contentType,'X-hbzw-Api-Key':'fcd8997d-e1a5-4c63-ba25-9e8e9c4cd882'}
    } else if(url.indexOf('https://prod-gateway.ehbapp.hubei.gov.cn/623c8c2e2c984b1b8fd842728a8b025d')>=0){
      header={'contentType': contentType}
    }else{
      header={'contentType': contentType}
    }

if(url.indexOf("ensureInfoController/cjyw")>=0){
  console.log(data)
}
    ehbAppJssdk.network.request({
      url: url,
      method: method,
      data: data,
      headers: header,
      success: function (res) {
        if(url.indexOf("ensureInfoController/cjyw")>=0){
          console.log(res)
        }
        ehbAppJssdk.notice.hidePreloader();
        resolve(res);
      },
      fail: function (res) {
        ehbAppJssdk.notice.alert({
          title: '提示',
          message: res.msg,
          buttonName: '收到',
        });
        ehbAppJssdk.notice.hidePreloader();
      }
    });
  })
}

/**
 * 请求nres接口
 * @param url
 * @param data
 * @param contentType
 * @param erroInfo
 * @returns {Promise<unknown>}
 */
export function requestNRES({url, data,contentType='application/json', erroInfo='查询失败！'}) {
  return new Promise((resolve, reject) => {
    ehbAppJssdk.notice.showPreloader({text: "正在查询中.."});
    ehbAppJssdk.network.request({
      url: Global.urlConfig.nres.request[Global.urlType] + '?appId=B20200924110527765CF13F&appKey=A2A9892DB6884542BFA1A3E4278641AA&nodeName=鄂州&t=1&version=1&url=http://10.0.0.4:8089/'+url,
      method: 'post',
      data: data,
      headers: {'contentType': contentType},
      success: function (res) {
        ehbAppJssdk.notice.hidePreloader();
        resolve(res);
      },
      fail: function (res) {
        ehbAppJssdk.notice.alert({
          title: '提示',
          message: res.msg,
          buttonName: '收到',
        });
        ehbAppJssdk.notice.hidePreloader();
      }
    });
  })
}

/**
 * 未查询到数据页面
 * @param info
 * @param close
 */
export function toNOData(info, close) {

  let closeCurrentPage = 1;
  if (close != null) {
    closeCurrentPage = close;
  }
  this.timer = setTimeout(() => {   //设置延迟执行
    ehbAppJssdk.notice.hidePreloader();
    ehbAppJssdk.operateWindow.open({
      title: '',
      url: absoultPath + "/noData",
      urlType: 'webPage',
      backRefresh: '1',
      reloadForLogin: '1',
      closeCurrentPage: closeCurrentPage,
      disableScrolling: 'disable',
      pageType: '1',
      pageLevel: '2',
      params: {
        info: info
      }
    });
  }, 1000);
}


export function goto(url,params) {
  ehbAppJssdk.operateWindow.open({
    title: '',
    url: url,
    urlType: 'webPage',
    backRefresh: '1',
    reloadForLogin: '1',
    closeCurrentPage: '0',
    disableScrolling: 'disable',
    pageType: '1',
    pageLevel: '2',
    params: params
  });
}
